package cn.wolfcode.wolf2w.util;

import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;

import org.springframework.data.mongodb.core.query.Query;


import java.util.List;

public class DBHelp {
    //在此说明<T>是个占位符
    public static <T> Page<T> query(MongoTemplate template,Class<T> clz,Pageable pageable,Query query) {

        long total = template.count(query, clz);
        if (total == 0){
            return  Page.empty();
        }
        query.with(pageable);

        List<T> list = template.find(query, clz);
        return new PageImpl<>(list, pageable, total);
    }
}
